<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
<title>用户</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../uploadjs/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.fileupload.js"></script>
<script type="text/javascript" src="../js/auth.js"></script>
<script type="text/javascript" src="../js/sha1.js"></script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" style="height:100px;background:#B3DFDA;padding:10px">
<div style="float:right;clear:both;margin-top:15px;margin-right:20px">
	<a href="javascript:logout()">注销</a>
	</div>
	<h2>蛋糕商城Rust版</h2>
	<h3>从2025为公众服务</h3>
</div>
<div data-options="region:'west',split:true,title:'主菜单'" style="width:180px;padding:0px;">
<div onclick="window.location='../pages/index.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">主页</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../custpages/admin/index.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">蛋糕商城后台</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/goodses.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">商品</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/custorders.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">订单</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/paytypes.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">支付方式</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/statuses.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">状态</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/orderitems.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">订单项</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/goodstypes.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">类型</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/recommends.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">推荐</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/roles.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">角色</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/permissions.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">许可</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/users.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">用户</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/profile.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">用户资料</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkrolepermission.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接角色许可</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkuserrole.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接用户角色</div><div class="menu-icon icon-add"></div></div>
</div>
<div data-options="region:'east',split:true,collapsed:true,title:'属性'" style="width:250px;overflow: hidden">
</div>
<div data-options="region:'south',border:false" style="height:40px;background:#A9FACD;padding:10px;text-align: center">
	蛋糕商城
</div>
<div data-options="region:'center',title:'Rust语言通用代码生成器：莲花　生成结果'">
<div style="margin:20px 0"></div>
<div class="easyui-panel" title="更新用户资料" style="width:700px">
<div style="padding:10px 60px 20px 60px">
<form id="ff" method="post">
<table cellpadding="5">
<input type="hidden" name="id" id="id"/>
<tr><td>用户名:</td><td><input  class='easyui-textbox' type='text' name='userName' id='userName' value='' data-options="required:false"/></td></tr>
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='firstName' id='firstName' value='' data-options="required:false"/></td></tr>
<tr><td>姓:</td><td><input  class='easyui-textbox' type='text' name='lastName' id='lastName' value='' data-options="required:false"/></td></tr>
<tr><td>电子邮件:</td><td><input  class='easyui-textbox' type='text' name='email' id='email' value='' data-options="required:false"/></td></tr>
<tr><td>是否管理员:</td><td><input  class='easyui-textbox' type='text' name='isadmin' id='isadmin' value='' data-options="required:false"/></td></tr>
<tr><td>性别:</td><td><input  class='easyui-textbox' type='text' name='gender' id='gender' value='' data-options="required:false"/></td></tr>
<tr><td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td></tr>
<tr><td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td></tr>
<tr><td>描述:</td><td><textarea  class='easyui-textarea' type='text' name='description' id='description' data-options="required:false" cols='20' rows='4'></textarea></td></tr>
<tr><td>照片:</td><td><img name='photo' id='photo' width='500px' src='../images/blank.jpg'><br>
<input id="addUserPhotoFileupload" type="file" name="files[]" data-url="../controller/profileController/addUploadUserPhoto"><br></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateMyProfileUser()">更新用户资料</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wchangePassword').window('open');">修改密码</a>
</div>
</div>
</div>
<div class="easyui-window" title="设置密码" id="wchangePassword" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:600px;height:400px">
	<div style="padding:10px 60px 20px 60px">
	<form id="ffchangePassword" method="post">
	<input type="hidden" id="userName" name="userName">
	<table cellpadding="5">
		<tr><td>旧密码:</td><td><input class='easyui-textbox' type='password' name='oldPassword' id='oldPassword' value='' data-options="required:true"/></td></tr>
		<tr><td>新密码:</td><td><input class='easyui-textbox' type='password' name='password' id='password' value='' data-options="required:true"/></td></tr>
		<tr><td>确认新密码:</td><td><input class='easyui-textbox' type='password' name='confirmPassword' id='confirmPassword' value='' data-options="required:true"/></td></tr>
	</table>
	</form>
	<div style="text-align:center;padding:5px">
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="changeMyPasswordUser()">重设密码</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wchangePassword').window('close')">关闭</a>
</div>
</div>
</div>
</body>
<script type="text/javascript">
$(function () {
	$('#addUserPhotoFileupload').fileupload({
			autoUpload: true,
			dataType: 'json',
			async: false,
			success: function(data, textStatus) {
			if (data.success == true){
				$("#ff").find("#photo").prop("src","data:image/png;base64,"+data.rows)
			}
			},
			progressall: function (e, data) {
				var progress = parseInt(data.loaded / data.total * 100, 10);
			},
		});
});
$(document).ready(function(){
findMyProfileUser();
});
function findMyProfileUser(){
	$.ajax({
		type: "post",
		url: "../controller/profileController/findMyProfileUser",
		dataType: 'json',
		success: function(data, textStatus) {
			if (data.success) {
				var rows = data.rows;
				$("#ff").find("#id").val(rows["id"]);
				$("#ff").find("#userName").textbox("setValue",rows["userName"]);
				$("#ff").find("#firstName").textbox("setValue",rows["firstName"]);
				$("#ff").find("#lastName").textbox("setValue",rows["lastName"]);
				$("#ff").find("#email").textbox("setValue",rows["email"]);
				var isadminCheckboxs = $("#ff").find("input[name='isadmin']");
				for (var i=0;i<isadminCheckboxs.length;i++){
					if (isadminCheckboxs.get(i).value == ""+rows["isadmin"]) isadminCheckboxs.get(i).checked=true;
				}
				$("#ff").find("#gender").textbox("setValue",rows["gender"]);
				$("#ff").find("#address").textbox("setValue",rows["address"]);
				$("#ff").find("#phone").textbox("setValue",rows["phone"]);
				$("#ff").find("#description").val(rows["description"]);
				if (!isBlank(rows["photo"]))	{
					$("#ff").find("#photo").prop("src","data:image/png;base64,"+rows["photo"]);
				}else{
					$("#ff").find("#photo").prop("src","../images/blank.jpg");
				}
				var checkboxs = $("#ff").find("input[name='active']");
				for (var i=0;i<checkboxs.length;i++){
					if (checkboxs.get(i).value == ""+rows["active"]) checkboxs.get(i).checked=true;
				}
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function changeMyPasswordUser(){
	var password = $("#ffchangePassword").find("#password").val();
	var oldPassword = $("#ffchangePassword").find("#oldPassword").val();
	var confirmPassword = $("#ffchangePassword").find("#confirmPassword").val();
	if (isBlank(oldPassword)){
		$.messager.alert("错误","旧密码不可为空！","error");
		return;
	}
	if (isBlank(password)||isBlank(confirmPassword)){
		$.messager.alert("错误","新密码不可为空！","error");
		return;
	}
	if (oldPassword == password){
		$.messager.alert("错误","新密码和旧密码不可相同！","error");
		return;
	}
	if (password!=confirmPassword){
		$.messager.alert("错误","新密码不匹配！","error");
		return;
	}
	$.ajax({
		type: "post",
		url: "../controller/profileController/changeMyPasswordUser",
		data:  {
			password:hex_sha1(password),
			oldPassword:hex_sha1(oldPassword),
		},
		dataType: 'json',
		success: function(data, textStatus) {
			if (data.success) {
				$("#wchangePassword").window("close");
				$.messager.alert("成功","成功修改密码！","info");
			} else if (!data.success) {
				$("#wchangePassword").window("close");
				$.messager.alert("失败","修改密码失败！","error");
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function updateMyProfileUser(){
	if (isBlank($("#ff").find("#userName").val())){
		$.messager.alert("错误","必须字段用户名为空！","error");
		return;
	}
	$.ajax({
		type: "post",
		url: "../controller/profileController/updateMyProfileUser",
		data: JSON.stringify({
			userName:$("#ff").find("#userName").val(),
			firstName:$("#ff").find("#firstName").val(),
			lastName:$("#ff").find("#lastName").val(),
			email:$("#ff").find("#email").val(),
			isadmin:parseBoolean($("#ff").find("input[name='isadmin']:checked").val()),
			gender:$("#ff").find("#gender").val(),
			address:$("#ff").find("#address").val(),
			phone:$("#ff").find("#phone").val(),
			description:$("#ff").find("#description").val(),
			photo:$("#ff").find("#photo").val(),
			active:parseBoolean($("#ff").find("input[name='active']:checked").val()),
		}),
		dataType: 'json',
		contentType:"application/json;charset=UTF-8",
		success: function(data, textStatus) {
			if (data.success) {
				$('#ff').form('clear');
				$.messager.alert("信息","更新用户资料成功！","info");
				findMyProfileUser();
			} else if (data.success == false){
				$.messager.alert("错误","更新用户资料失败！","error");
				findMyProfileUser();
			}
			},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function parseBoolean(val){
	if (val == undefined|| val == null) return false;
	var isInt = /^(-}+)?\d+$/.test(val);
	if (isInt&& val == "0") return false;
	else if (isInt&& val == "1") return true;
	else if (val.toLowerCase() == "false") return false;
	else if (val.toLowerCase() == "true") return true;
	else if (val.toLowerCase() == "f") return false;
	else if (val.toLowerCase() == "t") return true;
	else if (val.toLowerCase() == "n") return false;
	else if (val.toLowerCase() == "y") return true;
	else if (val.toLowerCase() == "no") return false;
	else if (val.toLowerCase() == "yes") return true;
	else return "";
}

function parseBooleanInt(val){
	var b = parseBoolean(val);
	if (b==undefined||b==null) return 0;
	else if (b==true) return 1;
	else return 0;
}

function parseIntNeg(val){
	if (isBlank(val) || parseInt(val) <= 0) return -1;
	else return parseInt(val);
}

function isBlank(val){
	if (val == undefined|| val == null || val == "" || val== "0" || val == 0) return true;
	else return false;
}

</script>
</html>
